BugĀ 602099 - Actions can be activatable too
authorMatthew Barnes <mbarnes@redhat.com>
Tue, 15 Dec 2009 13:00:44 +0000 (08:00 -0500)
committerMatthew Barnes <mbarnes@redhat.com>
Tue, 15 Dec 2009 13:05:11 +0000 (08:05 -0500)
Add a couple type checks in gtk_activatable_do_set_related_action() to
allow both GtkWidgets and GtkActions to implement GtkActivatable.  Bug
602099 describes a use case for this.

Also add a GObject prerequisite to the GtkActivatable interface.

gtk/gtkactivatable.c

index 4f92e524ea9fa7fbc9a23c13784581566f84e81f..4aa1b366f1bff7c2676a9dcf2ff8ceb7ef3e0f68 100644 (file)
@@ -276,13 +276,16 @@ gtk_activatable_get_type (void)
 {
   static GType activatable_type = 0;
 
-  if (!activatable_type)
+  if (!activatable_type) {
     activatable_type =
       g_type_register_static_simple (G_TYPE_INTERFACE, I_("GtkActivatable"),
                                     sizeof (GtkActivatableIface),
                                     (GClassInitFunc) gtk_activatable_class_init,
                                     0, NULL, 0);
 
+    g_type_interface_add_prerequisite (activatable_type, G_TYPE_OBJECT);
+  }
+
   return activatable_type;
 }
 
@@ -445,7 +448,9 @@ gtk_activatable_do_set_related_action (GtkActivatable *activatable,
        {
          g_signal_handlers_disconnect_by_func (prev_action, gtk_activatable_action_notify, activatable);
          
-         _gtk_action_remove_from_proxy_list (prev_action, GTK_WIDGET (activatable));
+          /* Check the type so that actions can be activatable too. */
+          if (GTK_IS_WIDGET (activatable))
+            _gtk_action_remove_from_proxy_list (prev_action, GTK_WIDGET (activatable));
          
           /* Some apps are using the object data directly...
            * so continue to set it for a bit longer
@@ -477,7 +482,8 @@ gtk_activatable_do_set_related_action (GtkActivatable *activatable,
 
          g_signal_connect (G_OBJECT (action), "notify", G_CALLBACK (gtk_activatable_action_notify), activatable);
 
-         _gtk_action_add_to_proxy_list (action, GTK_WIDGET (activatable));
+          if (GTK_IS_WIDGET (activatable))
+            _gtk_action_add_to_proxy_list (action, GTK_WIDGET (activatable));
 
           g_object_set_data (G_OBJECT (activatable), "gtk-action", action);
        }